package com.tianbo.service.imp;

import com.tianbo.common.ModelAndPage;
import com.tianbo.mapper.TOlapDatasetMapper;
import com.tianbo.model.TOlapDataset;
import com.tianbo.model.TOlapDatasetExample;
import com.tianbo.service.OlapDataSetService;
import com.tianbo.util.dao.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Mr.Xu on 2017/9/12.
 */
@Service
public class OlapDataSetImpl  implements OlapDataSetService {
    @Autowired
    private TOlapDatasetMapper tOlapDatasetMapper;
    public List<TOlapDataset> findOlapDataSet()throws Exception{
        TOlapDatasetExample olapDatasetExample=new TOlapDatasetExample();
        List<TOlapDataset> olapDatasetList=tOlapDatasetMapper.selectByExample(olapDatasetExample);
        return  olapDatasetList;

    }
    public ModelAndPage findOlapDataSet(int start, int pagelenth)throws Exception{
        TOlapDatasetExample tOlapDatasetExample=new TOlapDatasetExample();
        Page page=new Page(start,pagelenth);
        tOlapDatasetExample.setPage(page);
        int count=tOlapDatasetMapper.countByExample(tOlapDatasetExample);
        page.setCount(count);
        List<TOlapDataset> tOlapDatasetList=tOlapDatasetMapper.selectByExample(tOlapDatasetExample);
        ModelAndPage<TOlapDataset> modelAndPage=new ModelAndPage<TOlapDataset>(tOlapDatasetList,page);
        return modelAndPage;
    }
    public void addOlapDataSet(TOlapDataset olapDataset){
        tOlapDatasetMapper.insert(olapDataset);
    }
    public int deleteOlapDataset(BigDecimal datasetid){ tOlapDatasetMapper.deleteByPrimaryKey(datasetid); return  1;}
    public TOlapDataset findByid(BigDecimal datasetid) throws Exception{
        TOlapDataset olapDataset=new TOlapDataset();
        olapDataset=tOlapDatasetMapper.selectByPrimaryKey(datasetid);
        return olapDataset;
    }
    public void updateOlapDataset(TOlapDataset olapDataset){tOlapDatasetMapper.updateByPrimaryKey(olapDataset);}
}
